﻿using SimpleTasks.Domain.Repositories;
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NHibernate.Linq;

namespace SimpleTasks.Persistence.Hibernate
{
   public class HibernateRepository<T> : IRepository<T>
   {
      private HibernateUnitOfWork _currentUnitOfWork;

      public HibernateRepository(HibernateUnitOfWork unitOfWork)
      {
         Contract.Requires(unitOfWork != null);

         _currentUnitOfWork = unitOfWork;
      }

      public void Save(T item)
      {
         _currentUnitOfWork.CurrentSession.Save(item);
      }

      public T Get(object id)
      {
         return _currentUnitOfWork.CurrentSession.Get<T>(id);
      }

      public IQueryable<T> Query()
      {
         return _currentUnitOfWork.CurrentSession.Query<T>();
      }
   }
}
